<template>
  <div class="orderlist_wrap">
    <ul>
      <li v-for="(item, index) in list" :key="index">
        <div class="orderItem_hd">
          <span class="orderItem_time">{{ item.created_at }}</span>
          <span class="orderItem_statu">{{
            orderStatusFilter(item.status)
          }}</span>
          <div class="clear"></div>
        </div>
        <div v-for="good in item.commodity" class="orderItem_bd">
          <div class="orderItem_cont_lt">
            <img :src="good.img" alt="" />
          </div>
          <div class="orderItem_cont_middle">
            <p class="orderItem_name">{{ good.name }}</p>
            <p class="orderItem_describe">{{ good.spec }}</p>
          </div>
          <div class="orderItem_cont_rt">
            <p class="orderItem_price">￥{{ good.price }}</p>
            <p class="orderItem_num">x{{ good.number }}</p>
          </div>
          <div class="clear"></div>
        </div>
        <div class="orderItem_ft">
          <span class="orderItem_user">购买人：{{ item.user.nickname }}</span>
          <span class="orderItem_back">返：￥{{ item.bonus }}</span>
          <span class="orderItem_total"
            >共{{ item.commodity_sum }}件<img
              class=""
              src="@/assets/车主宝首页改-assets/返回.png"
              alt=""
          /></span>
          <div class="clear"></div>
        </div>
        <div v-if="-(-item.add_to)" class="footer">
          <div class="left">
            <span>线上支付：</span>{{ item.payment }} <span>尾款支付：</span
            >{{ item.add_to }}
          </div>
          <div
            @click="
              show[index] = true;
              $forceUpdate();
              $previewRefresh();
            "
            class="right"
          >
            支付凭证
          </div>
        </div>
        <div
          v-if="show[index] === true"
          @click="
            show[index] = false;
            $forceUpdate();
          "
          @touchmove.prevent
          class="preview-container"
        >
          <img
            @click.stop
            v-for="(img, index) in item.add_img"
            :key="index"
            preview="item.order_no"
            :src="img"
          />
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: ["list"],
  data() {
    return {
      show: []
    };
  },
  watch: {
    list: function(val) {
      this.show = new Array(val.length).fill(false);
    }
  },
  beforeRouteLeave(to, from, next) {
    next(false);
  },
  methods: {
    imgPrevew() {
      this.show = true;
    },
    orderStatusFilter(status) {
      switch (status) {
        case 0:
          return "待付款";
          break;
        case 2:
          return this.is_serve === 1 ? "待服务" : "待发货";
          break;
        case 3:
          return this.is_serve === 1 ? "" : "待收货";
          break;
        case 4:
          return "待评价";
          break;
        case 5:
          return "售后未完成";
          break;
        case -2:
          return "售后已完成";
          break;
        case -1:
          return "已取消";
          break;
      }
    }
  }
};
</script>

<style lang="less" scoped>
.clear {
  clear: both;
}

.orderlist_wrap {
  li {
    margin: 0.5rem 0 0.52rem 0;
    .preview-container {
      position: fixed;
      padding: 0.24rem;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      background: #fff;
      img {
        width: 5rem;
        height: 5rem;
        object-fit: cover;
      }
    }
    .footer {
      display: flex;
      justify-content: space-between;
      padding: 0.48rem 3.2%;
      font-size: 0.52rem;
      background: #fff;
      span {
        color: #666;
      }
      .right {
        color: #ee0a1e;
        text-decoration: underline;
      }
    }
    .orderItem_hd {
      background: #ffffff;
      padding: 0.5rem 0;

      .orderItem_time {
        color: #444444;
        font-size: 0.64rem;
        float: left;
        margin-left: 0.5rem;
      }

      .orderItem_statu {
        color: #ee0a1e;
        font-size: 0.52rem;
        float: right;
        margin-right: 0.5rem;
      }
    }

    .orderItem_bd {
      margin: 0.4rem 0;
      padding: 0 3.2%;
      .orderItem_cont_lt {
        float: left;
        height: 3.2rem;
        width: 3.2rem;
        overflow: hidden;
        background-color: #dfdfdf;
        img {
          width: 100%;
          height: 100%;
        }
      }

      .orderItem_cont_middle {
        float: left;
        margin: 0.52rem 0 0 0.42rem;

        .orderItem_name {
          color: #444444;
          font-size: 0.56rem;
          margin-bottom: 0.62rem;
          width: 6.56rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .orderItem_describe {
          color: #999999;
          font-size: 0.48rem;
          width: 6.56rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }

      .orderItem_cont_rt {
        float: right;
        margin: 0.52rem 0 0 0.42rem;

        .orderItem_price {
          color: #444444;
          font-size: 0.64rem;
          width: 3rem;
          text-align: right;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          margin-bottom: 0.62rem;
        }

        .orderItem_num {
          color: #999999;
          font-size: 0.48rem;
          width: 3rem;
          text-align: right;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }

    .orderItem_ft {
      background: #ffffff;
      padding: 0.7rem 0;

      .orderItem_user {
        color: #444444;
        font-size: 0.56rem;
        float: left;
        margin-left: 0.5rem;
      }

      .orderItem_back {
        color: #ee0a1e;
        font-size: 0.56rem;
        float: left;
        margin-left: 0.92rem;
      }

      .orderItem_total {
        color: #444444;
        font-size: 0.56rem;
        float: right;

        img {
          width: 0.22rem;
          margin: 0 0.5rem 0 0.64rem;
        }
      }
    }
  }
}
</style>
